﻿using System;
using System.Collections.Generic;

namespace Chimp.Core
{
    public class DataList : JointNode
    {
        public DataList(Var v, JointNode p)
        {
            V = v;
            Data = new List<string>();

            SetData(p);
        }

        public Var V { get; set; }
        public List<string> Data { get; set; }

        public override void ParseNode()
        {
            if (GetTok() != "(")
            {
                Console.WriteLine("Expecting \"(\".");
            }
            while (!Eof)
            {
                string t = GetTok();
                if (t == ",") continue;
                if (t == ")")
                {
                    return;
                }
                Data.Add(t);
            }
        }

        public override void WriteOutput()
        {
            Console.WriteLine("Writing DataL2ist...");
            _cw.WriteLine(V.Name + ".Clear();");
            string enclose = "";
            switch (V.CurType)
            {
                case "String":
                    enclose = "";
                    break;
            }

            foreach (string d in Data)
            {
                _cw.WriteLine(V.Name + ".Add(" + enclose + d + enclose + ");");
            }
        }
    }
}